//
//  SLMacro.h
//  SLKit
//
//  Created by S_LINE on 2020/4/22.
//  Copyright © 2020 S_LINE. All rights reserved.
//

#ifndef SLMacro_h
#define SLMacro_h

#define SL_IS_IPAD ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)

// UI
#define SL_SCALE [UIScreen mainScreen].scale
#define SL_OnePixel (1.0 / [UIScreen mainScreen].scale)
#define SL_SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define SL_SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
// 实时状态栏高度（包含热点高度）
#define SL_STATUS_BAR_HEIGHT [UIApplication sharedApplication].statusBarFrame.size.height
#define SL_NAV_BAR_HEIGHT 44.0
#define SL_STATUS_BAR_AND_NAV_BAR_HEIGHT (SL_STATUS_BAR_HEIGHT + SL_NAV_BAR_HEIGHT)
#define SL_TABBAR_HEIGHT 49.0
#define SL_SAFE_AREA_TOP ({\
    CGFloat safeAreaTop = 0;\
    if (@available(iOS 11.0, *)) { \
        UIWindow *window = [[UIApplication sharedApplication].windows firstObject]; \
        safeAreaTop = window.safeAreaInsets.top; \
    } \
    safeAreaTop; \
})
#define SL_SAFE_AREA_BOTTOM ({\
    CGFloat safeAreaBottom = 0;\
    if (@available(iOS 11.0, *)) { \
        UIWindow *window = [[UIApplication sharedApplication].windows firstObject]; \
        safeAreaBottom = window.safeAreaInsets.bottom; \
    } \
    safeAreaBottom; \
})

#define SL_IS_IPHONEX_S ({\
    BOOL isBangsScreen = NO; \
    if (@available(iOS 11.0, *)) { \
        UIWindow *window = [[UIApplication sharedApplication].windows firstObject]; \
        isBangsScreen = window.safeAreaInsets.bottom > 0; \
    } \
    isBangsScreen; \
})

// 字体
#define SLFont(fontName, fontSize) [UIFont fontWithName:fontName size:fontSize] ?: [UIFont systemFontOfSize:fontSize]

// SYSTEM INFO
#define SL_SYSTEM_VERSION [[[UIDevice currentDevice] systemVersion] doubleValue]
#define SL_SYSTEM_VERSION_STRING [[UIDevice currentDevice] systemVersion]

//#if DEBUG
//#define NSLog(FORMAT, ...) fprintf(stderr,"\n%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
//#else
//#define NSLog(FORMAT, ...) nil
//#endif

#ifndef weakify
    #if DEBUG
        #if __has_feature(objc_arc)
        #define weakify(object) autoreleasepool{} __weak __typeof__(object) weak##_##object = object;
        #else
        #define weakify(object) autoreleasepool{} __block __typeof__(object) block##_##object = object;
        #endif
    #else
        #if __has_feature(objc_arc)
        #define weakify(object) try{} @finally{} {} __weak __typeof__(object) weak##_##object = object;
        #else
        #define weakify(object) try{} @finally{} {} __block __typeof__(object) block##_##object = object;
        #endif
    #endif
#endif

#ifndef strongify
    #if DEBUG
        #if __has_feature(objc_arc)
        #define strongify(object) autoreleasepool{} __typeof__(object) object = weak##_##object;
        #else
        #define strongify(object) autoreleasepool{} __typeof__(object) object = block##_##object;
        #endif
    #else
        #if __has_feature(objc_arc)
        #define strongify(object) try{} @finally{} __typeof__(object) object = weak##_##object;
        #else
        #define strongify(object) try{} @finally{} __typeof__(object) object = block##_##object;
        #endif
    #endif
#endif

#endif /* SLMacro_h */
